package com.flower.sequence.segment;

import com.flower.sequence.service.SegmentGenerator;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @author shanks on 2019-10-12
 */

public class DateSegmentGenerator implements SegmentGenerator {

    /**
     * 当前日期
     */
    private java.time.LocalDateTime   currentDate;
    /**
     * 日期格式，比如yyyy-MM-dd HH:mm:ss
     */
    private String pattern;
    /**
     * 流水号片段长度
     */
    private int    length;


    @Override
    public String getStringSegment() {
        DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern(pattern);
        String segmentString = ofPattern.format(currentDate);
        return segmentString;
    }

    public void setCurrentDate(LocalDateTime currentDate) {
        this.currentDate = currentDate;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    public void setLength(int length) {
        this.length = length;
    }
}
